﻿package  com.devilcat.ws{
	import com.devilcat.ws.Basicws;
	import com.worlize.websocket.*;
	import com.devilcat.dt.Pokemondt;
	import com.devilcat.dt.Gamedt;
	
	public class UpdatePokemonws extends Basicws{
		public function UpdatePokemonws() {
			super("iw-protocol");
		}
		public function Update(pokemon:Pokemondt,insert:Boolean=false,MoveAttack:String="",PVPTurn:Number=0){
			var pack:Object = new Object();
			pack.upid=pokemon.upid;
			pack.uid = Gamedt.Player.uid;
			pack.pid = pokemon.pid;
			pack.pmod = pokemon.pmod;
			pack.Name = pokemon.Name;
			pack.Status = pokemon.Status;
			pack.Ability = pokemon.Ability;
			pack.HP = pokemon.HP;
			pack.CurrentHP = pokemon.CurrentHP;
			pack.Attack = pokemon.Attack;
			pack.Defense = pokemon.Defense;
			pack.SpAtk = pokemon.SpAtk;
			pack.SpDef = pokemon.SpDef;
			pack.Speed = pokemon.Speed;
			pack.Move1 = pokemon.Move1.Name;
			pack.Move2 = pokemon.Move2.Name;
			pack.Move3 = pokemon.Move3.Name;
			pack.Move4 = pokemon.Move4.Name;
			pack.MoveAttack = MoveAttack;
			pack.PVPTurn = PVPTurn;
			if(insert)
				pack.action="inserpokemon";
			else
				pack.action="updatepokemon";
			var myJson:String = JSONString(pack);
			websocket.sendUTF(myJson);	
			if(insert)
				var lupl:UserPokemonws = new UserPokemonws(Gamedt.Player.uid);
		}
		override function handleWebSocketOpen(event:WebSocketEvent):void
		{
		}
		override function handleWebSocketMessage(event:WebSocketEvent):void
		{
			if (event.message.type === WebSocketMessage.TYPE_UTF8)
			{	
				//tes =	JSONObject(event.message.utf8Data);
				//trace("Got message: " + event.message.utf8Data);
			}
		}

	}
	
}
